%% generatePeriodicExtension
%
% Takes in pressure data, time, and signal period and generates periodic
% signal extension
%
%% Syntax
% [ExtendedPressureSignal] = generatePeriodicExtension(PressureData, Time, SignalPeriod)
%
% [ydata0] = generatePeriodicExtension(ydata, t, Tp)
%
%
%% Description
% Takes in pressure data, time, and signal period and generates periodic
% signal extension
%
%% Arguments
%* PressureData                  - Double: A double precision vector of
%                                        pressure valuesin dynes/cm^2
%
%* Time                          - Double: A double precision vector of
%                                        time values in seconds
%
%* SignalPeriod                  - Double: A double precision number of the
%                                       full signal period
%                                        
%
%% Returns
%* ExtendedPressureSignal         - Double: A double precision vector of
%                                         an extended signal
%
%* ExtendedTimeSignal               - Double: A double precision vector of
%                                         an extended time 
%                                   
%
%% Function Side Effects
%* N/A
%
%% Exceptions
%* An error is thrown if input is not of type double
%
%% See Also
% N/A

function [ExtendedTimeSignal,ExtendedPressureSignal] = generatePeriodicExtension(PressureData, Time, SignalPeriod)

    if isa(PressureData, 'double') ~=1
    type = class(PressureData);
    error(sprintf(('Pressure data is of type %s please change to type double'), type))
    
    end

    if isa(Time, 'double') ~=1
    type = class(PressureData);
    error(sprintf(('Time is of type %s please change to type double'), type))
    
    end

    if isa(SignalPeriod, 'double') ~=1
    type = class(SignalPeriod);
    error(sprintf(('Signal Period is of type %s please change to type double'), type))
    
    end



PressureData(end-1) = (PressureData(1)+PressureData(end-1))/2;  

PressureData(end-20:end-2)=[];

Time(end-20:end-2)=[];

PressureData(end)=PressureData(1);

ExtendedTimeSignal = [Time; (Time+SignalPeriod) ; (Time+2*SignalPeriod)]; % Create extension in time domain

ExtendedPressureSignal = [PressureData;PressureData;PressureData]; % Create signal extension


end


